import xadmin

from apps.operation.models import UserAsk, CourseComments, UserFavorite, UserMessage, UserCourse,Banner,VideoComments


class BannerAdmin(object):
    list_display = ["title", "url", "image", "index"]
    search_fields = ["title", "url", "image", "index"]
    list_filter = ["title", "url", "image", "index"]
    list_editable = ["title", "url", "image", "index"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-handshake-o'
class UserAskAdmin(object):
    list_display = ["name", "mobile", "course_name", "add_time"]
    search_fields = ["name", "mobile", "course_name"]
    list_filter = ["name", "mobile", "course_name", "add_time"]
    list_editable = ["name", "mobile", "course_name"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-comments-o'
class UserCourseAdmin(object):
    list_display = ["user", "course","add_time"]
    search_fields = ["user", "course"]
    list_filter = ["user", "course","add_time"]
    list_editable = ["user", "course"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-folder-o'
    def save_models(self):
        obj = self.new_obj
        if not obj.id:
            obj.save()
            course = obj.course
            course.students +=1
            course.save()

class UserMessageAdmin(object):
    list_display = ["user", "message", "has_read", "add_time"]
    search_fields = ["user", "message", "has_read"]
    list_filter = ["user", "message", "has_read", "add_time"]
    list_editable = ["user", "message", "has_read"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-bell-o'
class CourseCommentsAdmin(object):
    list_display = ["user", "course", "comments", "add_time"]
    search_fields = ["user", "course", "comments"]
    list_filter = ["user", "course", "comments", "add_time"]
    list_editable = ["user", "course", "comments"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-commenting-o'
class VideoCommentsAdmin(object):
    list_display = ["user", "video", "comments", "add_time"]
    search_fields = ["user", "video", "comments"]
    list_filter = ["user", "video", "comments", "add_time"]
    list_editable = ["user", "video", "comments"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-commenting-o'
class UserFavoriteAdmin(object):
    list_display = ["user", "fav_name","fav_id", "fav_type", "add_time"]
    search_fields = ["user", "fav_id", "fav_type"]
    list_filter = ["user", "fav_id", "fav_type", "add_time"]
    list_editable = ["user", "fav_id", "fav_type"]
    readonly_fields = ["add_time"]
    model_icon = 'fa fa-star-o'


xadmin.site.register(UserAsk, UserAskAdmin)
xadmin.site.register(UserCourse, UserCourseAdmin)
xadmin.site.register(UserMessage, UserMessageAdmin)
xadmin.site.register(CourseComments, CourseCommentsAdmin)
xadmin.site.register(VideoComments, VideoCommentsAdmin)
xadmin.site.register(UserFavorite, UserFavoriteAdmin)
xadmin.site.register(Banner, BannerAdmin)
